Add defensive ChildCount() guards in parseMain to prevent AST index-out-of-bounds panics#20
Closed
Copilot wants to merge 3 commits intoUpdate-packagesfrom
Closed
Add defensive ChildCount() guards in parseMain to prevent AST index-out-of-bounds panics#20Copilot wants to merge 3 commits intoUpdate-packagesfrom
Copilot wants to merge 3 commits intoUpdate-packagesfrom
Conversation
Migrate the Python file parser from recursive AST traversal to pre-compiled tree-sitter queries, add object pooling, and batch-parse all files into a lookup table to eliminate redundant work. Changes: - file_parser.go: Replace recursive parse() with query-based approach using pre-compiled tree-sitter queries (init-time), sync.Pool for parser and cursor reuse, and TYPE_CHECKING block detection. - parser.go: Add parseAllToLUT() for concurrent batch parsing with errgroup limited to NumCPU, and parseFromLUT() to process pre-parsed results without re-parsing. - generate.go: Parse all .py files once upfront into a LUT before target generation. Replace per-target parser.parse() calls with parseFromLUT() lookups. Replace per-call regexp.MustCompile in isDjangoTestFile with strings.Contains. Profiled on production codebase (cpu pprof): | Metric | Before | After | Improvement | |-------------|---------|---------|-------------| | Wall time | 46.72s | 13.25s | 3.5x faster | | CPU samples | 53.04s | 31.69s | 40% less | | cgocall | 28.13s | 23.68s | 16% less | Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merged
…nexpected AST shapes Co-authored-by: ewianda <7077790+ewianda@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update package based on feedback from PR #19 review
Add defensive ChildCount() guards in parseMain to prevent AST index-out-of-bounds panics
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
parseMainaccessedchild.Child(1).Child(1)andstatement.Child(2)without verifying child counts, risking panics on malformed or unexpected AST shapes (e.g., syntax errors, non-standard comparison forms).Changes
python/file_parser.go: Addedchild.Child(1).ChildCount() > 2guard before accessing the comparison operator's children. Sincestatementaliaseschild.Child(1), this single check also covers thestatement.Child(0)andstatement.Child(2)accesses downstream.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.